package com.ruoyi.apparatus.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.apparatus.domain.AlgsExperimentalApparatus;
import com.ruoyi.apparatus.service.IAlgsExperimentalApparatusService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 实验器材Controller
 * 
 * @author ruoyi
 * @date 2023-03-17
 */
@RestController
@RequestMapping("/apparatus")
public class AlgsExperimentalApparatusController extends BaseController
{
    @Autowired
    private IAlgsExperimentalApparatusService algsExperimentalApparatusService;

    /**
     * 查询实验器材列表
     */
//    @RequiresPermissions("test:apparatus:list")
    @GetMapping("/list")
    public TableDataInfo list(AlgsExperimentalApparatus algsExperimentalApparatus)
    {
        startPage();
        List<AlgsExperimentalApparatus> list = algsExperimentalApparatusService.selectAlgsExperimentalApparatusList(algsExperimentalApparatus);
        return getDataTable(list);
    }

    /**
     * 导出实验器材列表
     */
//    @RequiresPermissions("test:apparatus:export")
//    @Log(title = "实验器材", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AlgsExperimentalApparatus algsExperimentalApparatus)
    {
        List<AlgsExperimentalApparatus> list = algsExperimentalApparatusService.selectAlgsExperimentalApparatusList(algsExperimentalApparatus);
        ExcelUtil<AlgsExperimentalApparatus> util = new ExcelUtil<AlgsExperimentalApparatus>(AlgsExperimentalApparatus.class);
        util.exportExcel(response, list, "实验器材数据");
    }

    /**
     * 获取实验器材详细信息
     */
//    @RequiresPermissions("test:apparatus:query")
    @GetMapping(value = "/{experimentalApparatusId}")
    public AjaxResult getInfo(@PathVariable("experimentalApparatusId") Long experimentalApparatusId)
    {
        return success(algsExperimentalApparatusService.selectAlgsExperimentalApparatusByExperimentalApparatusId(experimentalApparatusId));
    }

    /**
     * 新增实验器材
     */
//    @RequiresPermissions("test:apparatus:add")
    @Log(title = "实验器材", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AlgsExperimentalApparatus algsExperimentalApparatus)
    {
        return toAjax(algsExperimentalApparatusService.insertAlgsExperimentalApparatus(algsExperimentalApparatus));
    }

    /**
     * 修改实验器材
     */
//    @RequiresPermissions("test:apparatus:edit")
//    @Log(title = "实验器材", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AlgsExperimentalApparatus algsExperimentalApparatus)
    {
        return toAjax(algsExperimentalApparatusService.updateAlgsExperimentalApparatus(algsExperimentalApparatus));
    }

    /**
     * 删除实验器材
     */
//    @RequiresPermissions("test:apparatus:remove")
//    @Log(title = "实验器材", businessType = BusinessType.DELETE)
	@DeleteMapping("/{experimentalApparatusIds}")
    public AjaxResult remove(@PathVariable Long[] experimentalApparatusIds)
    {
        return toAjax(algsExperimentalApparatusService.deleteAlgsExperimentalApparatusByExperimentalApparatusIds(experimentalApparatusIds));
    }
}
